﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Activities;
using System.Activities.Runtime;
using System.DirectoryServices;

namespace Vision.Core.ActivityComponents.ActiveDirectory
{
    public class GetADPropertyValue : CodeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<string> LdapPropertyName { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public OutArgument<object> LdapPropertyValue { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        public InArgument<DirectoryEntry> CurrentEntry { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            object adEntry = ActiveDirectoryHelper.GetEntryValue(context.GetValue(this.CurrentEntry), context.GetValue(this.LdapPropertyName));
            context.SetValue(this.LdapPropertyValue, adEntry);            
        }
    }    
}
